package com.duqc.web.service.impl;

import com.duqc.web.dao.ShardingSphereMapper;
import com.duqc.web.dto.ShardingSphereDTO;
import com.duqc.web.service.ShardingSphereService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName ShardingSphereServiceImpl
 * @Description TODO
 * @Author duqc
 * @Date 2021/4/7
 **/
@Service
@RequiredArgsConstructor
@Slf4j
public class ShardingSphereServiceImpl implements ShardingSphereService {

    private final ShardingSphereMapper shardingSphereMapper;

    @Override
    public void addInfo(ShardingSphereDTO shardingSphereDTO) {
        this.shardingSphereMapper.addInfo(shardingSphereDTO);
    }

    @Override
    public List<ShardingSphereDTO> listInfo() {
//        for (int i = 0; i < 100; i++) {
//            ThreadPoolUtil.getPool().execute(new listInfo(shardingSphereMapper));
//        }
        return this.shardingSphereMapper.listInfo();
    }

    private class listInfo implements Runnable {
        private final ShardingSphereMapper shardingSphereMapper;

        public listInfo(ShardingSphereMapper shardingSphereMapper) {
            this.shardingSphereMapper = shardingSphereMapper;
        }

        @Override
        public void run() {
            this.shardingSphereMapper.listInfo();
        }
    }
}
